package com.aaa.system.controller.api;

import com.aaa.entity.User;
import com.aaa.system.service.UserService;
import com.aaa.system.vo.UserVo;
import com.aaa.utils.JwtUtils;
import com.aaa.utils.WebUtil;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: aaa-his-parent
 * @description:
 * @author: 闫克起2
 * @create: 2023-12-07 12:07
 * api: 供前端用--Result
 **/
@RestController
@RequestMapping("/system/api/user")
public class ApiUserController {
    @Autowired
    private UserService userService;

    @GetMapping("/info")
    public Result<User> info() {
        String token = WebUtil.getRequest().getHeader("token");
        String phone = JwtUtils.getClaimByName(token);
        User user = userService.findUserByPhone(phone);
        return new Result<>(200, "查询成功", user);
    }

    @Autowired
    private StringRedisTemplate redisTemplate;

    @GetMapping("/logout")
    public Result<Void> logout() {
        String token = WebUtil.getRequest().getHeader("token");
        redisTemplate.delete("user:" + token);
        return new Result<>(200, "退出成功", null);
    }

    @PostMapping("findUserByCond")
    public Result<Page<User>> findUserByCond(@RequestBody UserVo userVo) {
        Page<User> page = userService.selectUserByCond(userVo);
        return new Result<>(200, "查询成功", page);
    }

    @GetMapping("getSchedulingUser")
    public Result<List<User>> getSchedulingUser(){
        List<User> users=userService.findSchedulingUser();
        return new Result<>(200, "查询成功", users);
    }
}




